﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BuySoftwareOnline.Domain.Abstract;

namespace BuySoftwareOnline.Domain.Concrete
{
    public class AdvertiseRepository : IAdvertiseRepository
    {
        private BuySoftwareOnlineDataContext context;

        public AdvertiseRepository()
        {
            context = new BuySoftwareOnlineDataContext();
        }

        public IQueryable<Advertise> Advertises
        {
            get { return context.Advertises; }
        }

        public void SaveAdvertise(Advertise advertise)
        {
            if (advertise.AdvertiseID == 0)
            {
                context.Advertises.InsertOnSubmit(advertise);
            }
            else
            {
                context.Advertises.Attach(advertise);
                context.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, advertise);
            }
            context.SubmitChanges();
        }

        public void DeleteAdvertise(Advertise advertise)
        {
            context.Advertises.DeleteOnSubmit(advertise);
            context.SubmitChanges();
        }
    }
}
